package com.sky.mapper;

import com.sky.dto.DishDTO;
import com.sky.entity.Category;
import com.sky.entity.Dish;
import com.sky.entity.DishFlavor;
import com.sky.pojo.StatusUpdate;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DishMapper {

    // 分页查询
    @Select("select dish.id, dish.name, category_id, price, image, description, dish.status, " +
            "dish.update_time, category.name as categoryName from dish left join category  on dish.category_id = category.id")
    List<DishVO> list();

    @Select("select dish.id, dish.name, category_id, price, image, description, dish.status, " +
            "dish.update_time, category.name as categoryName " +
            "from dish left join category  on dish.category_id = category.id where dish.id = #{id}")
    DishVO getById(Long id);


    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    @Insert("insert into dish(name, category_id, price, image, description," +
            " status, create_time, update_time, create_user, update_user) " +
            "values (#{name}, #{categoryId}, #{price}, #{image}, #{description}," +
            " #{status}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser}" +
            ")")
    void addDish(Dish dish);

    @Select("select id, name, category_id, price, image, description, status, " +
            "create_time, update_time, create_user, update_user from dish " +
            "where category_id = #{categoryId}")
    List<Dish> listByCategoryId(Integer categoryId);



    @Delete("delete from dish_flavor where dish_id = #{dishId}")
    void deleteByDish(Long dishId);

    @Update("update dish set status=#{status} where id =#{id}")
    void status(StatusUpdate statusUpdate);

    void deleteByIds(Long[] ids);


    @Select("select * from dish where id = #{id}")
    Dish getByShoppingCartId(Long id);

    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    @Delete("delete from dish where id = #{id}")
    void deleteById(Long id);

    void update(Dish dish);
    @Select("select a.* from dish a left join setmeal_dish b on a.id = b.dish_id where b.setmeal_id = #{setmealId}")
    List<Dish> getBySetmealId(Long id);
}
